# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

_gemname='parallel_tests'
pkgname="ruby-${_gemname}"
pkgver=3.12.1
pkgrel=1
pkgdesc='Run Test::Unit / RSpec / Cucumber / Spinach in parallel'
arch=('any')
url="https://github.com/grosser/${_gemname}"
license=('MIT')
depends=('ruby' 'ruby-parallel')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('cf00de81c500478301b8a462dc6db8745445bda0ba49a70b8afd230db27188304b9c5ef4c9cbfd283a59ccd5055e4a01516e8a94d12be5208649651d2946279b')

prepare() {
  cd "${_gemname}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"
}

build() {
  cd "${_gemname}-${pkgver}"

  gem build "${_gemname}.gemspec"
}

# https://github.com/grosser/spinach is not packaged yet
#check() {
#  cd "${_gemname}-${pkgver}"
#
#  rake --tasks
#}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}/${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    "${_gemname}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "${pkgdir}/${_gemdir}/cache/" \
    "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/vendor/" \
    "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"

  find "${pkgdir}/${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "${pkgdir}/${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install --verbose -D --mode=0644 Readme.md "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}
